﻿using System;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Text;
using System.Data;
using System.Data.SqlClient;

/// <summary>
///Album_Photo 的摘要说明
/// </summary>
public class Album_Photo
{
	public Album_Photo()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}

    /// <summary>
    /// 获取对应用户的相册列表
    /// </summary>
    /// <param name="UserId"></param>
    /// <returns></returns>
    public DataTable GetAllAlbumByUser(int UserId)
    {
        SqlHelper Helper = new SqlHelper();
        string CmdText = " SELECT * FROM _Album WHERE _UID = @UserId";
        SqlParameter[] parm = new SqlParameter[]
        {
            new SqlParameter("@UserId",UserId)
        };
        SqlCommand mycommand = Helper.GetCommand(CmdText, parm);
        DataTable dt = new DataTable();
        using (SqlDataReader mysqldatareader = mycommand.ExecuteReader())
        {
            dt.Load(mysqldatareader);
        }
        return dt;
    }

    /// <summary>
    /// 增加相册
    /// </summary>
    /// <param name="Album_Name"></param>
    /// <param name="Album_Info"></param>
    /// <param name="Album_UpdateTime"></param>
    /// <param name="UserId"></param>
    /// <param name="CoverPhotoUrl"></param>
    public void AddAlbum(string Album_Name, string Album_Info, DateTime Album_UpdateTime, int UserId, string CoverPhotoUrl)
    {
        SqlHelper Helper = new SqlHelper();
        string CmdText = "INSERT INTO _Album(_Name,_Info,_AddTime,_UpdateTime,_UId,_CoverPhotoUrl) VALUES(@Name,@Info,@Time,@Time,@UId,@Url)";
        SqlParameter[] parm = new SqlParameter[]
        {
            new SqlParameter("@Name",Album_Name),
            new SqlParameter("@Info",Album_Info),
            new SqlParameter("@Time",Album_UpdateTime),
            new SqlParameter("@UId",UserId),
            new SqlParameter("@Url",CoverPhotoUrl)
        };
        SqlCommand mycommand = Helper.GetCommand(CmdText, parm);
        mycommand.ExecuteNonQuery();
    }

    /// <summary>
    /// 更新相册
    /// </summary>
    /// <param name="Album_ID"></param>
    /// <param name="Album_Name"></param>
    /// <param name="Album_Info"></param>
    /// <param name="Album_UpdateTime"></param>
    /// <param name="UserId"></param>
    /// <param name="CoverPhotoUrl"></param>
    public void UpdateAlbum(int Album_ID,string Album_Name, string Album_Info, DateTime Album_UpdateTime, int UserId, string CoverPhotoUrl)
    {
        SqlHelper Helper = new SqlHelper();
        string CmdText = "UPDATE _Album SET _Name=@Name,_Info=@Info,_UpdateTime=@Time,_CoverPhotoUrl=@Url WHERE _Id=@Id";
        SqlParameter[] parm = new SqlParameter[]
        {
            new SqlParameter("@Id",Album_ID),
            new SqlParameter("@Name",Album_Name),
            new SqlParameter("@Info",Album_Info),
            new SqlParameter("@Time",Album_UpdateTime),
            new SqlParameter("@Url",CoverPhotoUrl)
        };
        SqlCommand mycommand = Helper.GetCommand(CmdText, parm);
        mycommand.ExecuteNonQuery();
    }

    /// <summary>
    /// 删除相册
    /// </summary>
    /// <param name="Album_ID"></param>
    public void DeleteAlbum(int Album_ID)
    {
        SqlHelper Helper = new SqlHelper();
        string CmdText = "DELETE _Album WHERE _Id=@Id";
        SqlParameter[] parm = new SqlParameter[]
        {
            new SqlParameter("@Id",Album_ID)
        };
        SqlCommand mycommand = Helper.GetCommand(CmdText, parm);
        mycommand.ExecuteNonQuery();
    }

    /// <summary>
    /// 获取相应相册里的所有照片
    /// </summary>
    /// <param name="Album_Id"></param>
    /// <returns></returns>
    public DataTable GetAllPhotoByAlbum(int Album_Id)
    {
        SqlHelper Helper = new SqlHelper();
        string CmdText = "SELECT * FROM _PHOTO WHERE _AlbumId = @AId";
        SqlParameter[] parm = new SqlParameter[]
        {
            new SqlParameter("@AId",Album_Id)
        };
        SqlCommand mycommand = Helper.GetCommand(CmdText, parm);
        DataTable dt = new DataTable();
        using (SqlDataReader mysqldatareader = mycommand.ExecuteReader())
        {
            dt.Load(mysqldatareader);
        }
        return dt;
    }

    /// <summary>
    /// 添加照片
    /// </summary>
    /// <param name="Album_Id"></param>
    /// <param name="Info"></param>
    /// <param name="Time"></param>
    /// <param name="PhotoUrl"></param>
    public void AddPhoto(int Album_Id, string Info, DateTime Time, string PhotoUrl)
    {
        SqlHelper Helper = new SqlHelper();
        string CmdText = "INSERT INTO _PHOTO(_Info,_AlbumId,_AddTime,_Url,_UpdateTime) VALUES(@Info,@AlbumId,@Time,@Url,@Time)";
        SqlParameter[] parm = new SqlParameter[]
        {
            new SqlParameter("@Info",Info),
            new SqlParameter("@AlbumId",Album_Id),
            new SqlParameter("@Time",Time),
            new SqlParameter("@Url",PhotoUrl)
        };
        SqlCommand mycommand = Helper.GetCommand(CmdText, parm);
        mycommand.ExecuteNonQuery();
    }

    /// <summary>
    /// 更行图片信息
    /// </summary>
    /// <param name="PhotoId"></param>
    /// <param name="Info"></param>
    /// <param name="Time"></param>
    /// <param name="PhotoUrl"></param>
    public void UpdatePhoto(int PhotoId,string Info, DateTime Time, string PhotoUrl)
    {
        SqlHelper Helper = new SqlHelper();
        string CmdText = "UPDATE _PHOTO SET _Info=@Info,_UpdateTime=@Time,_Url=@Url WHERE _Id=@PId ";
        SqlParameter[] parm = new SqlParameter[]
        {
            new SqlParameter("@PId",PhotoId),
            new SqlParameter("@Info",Info),
            new SqlParameter("@Time",Time),
            new SqlParameter("@Url",PhotoUrl)
        };
        SqlCommand mycommand = Helper.GetCommand(CmdText, parm);
        mycommand.ExecuteNonQuery();
    }

    /// <summary>
    /// 删除图片信息
    /// </summary>
    /// <param name="PhotoId"></param>
    public void DeletePhoto(int PhotoId)
    {
        SqlHelper Helper = new SqlHelper();
        string CmdText = "DELETE _PHOTO WHERE _Id = @PId";
        SqlParameter[] parm = new SqlParameter[]
        {
            new SqlParameter("@PId",PhotoId)
        };
        SqlCommand mycommand = Helper.GetCommand(CmdText, parm);
        mycommand.ExecuteNonQuery();
    }
}
